package javaCode.chapter16.state_;

/**
 * @author 徐州城
 * @version 1.0
 */
public class ThreadState_ {
    public static void main(String[] args) throws InterruptedException {

        T t = new T();
        System.out.println(t.getName() + " 状态 " + t.getState());
        t.start();

        while (Thread.State.TERMINATED != t.getState()){//如果线程的状态terminated不等于 t.getState 就执行
            System.out.println(t.getName() + " 状态 " + t.getState());
            Thread.sleep(500);
        }

        System.out.println(t.getName() + " 状态 " + t.getState());
    }
}

class T extends Thread{

    @Override
    public void run() {
        while (true) {

            for (int i = 1; i <= 10; i++) {
                System.out.println("hi " + i);

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            break;
        }
    }

}
